
import { loadYoga } from "yoga-layout/load";
function capitalize(s: string) {
  return "set" + s[0].toUpperCase() + s.slice(1);
}
let Yoga: any;
loadYoga().then((mod) => (Yoga = mod));
function applyYogaProps(yogaNode, props) {
  Object.entries(props).forEach(([key, value]) => {
    const handle = capitalize(key);
    if (value !== undefined && yogaNode[handle]) {
      console.log(value);
      yogaNode[handle](value);
    }
  });
}
export function useFlex(props, children = []) {
  let node = null;
  const style = { ...props };
  const childNodes = [...children]; 
  if (!Yoga) return;

  if (!node) {
    node = Yoga.Node.create();
  }
  applyYogaProps(node, style);

  childNodes.forEach((child) => {
    if (child.node) {
      node.insertChild(child.node, node.getChildCount());
    }
  });
  return { node, style, children: childNodes };
}
